include "base.thrift"
include "course.thrift"
include "user.thrift"

struct Post{
    1: optional i32 post_id;
    2: string title; // 标题
    4: list<course.Directory> directories; // 关联分组
    5: optional string last_replied_at; // 最新回复时间
    6: optional list<user.Member> repliers; // 解答人
    7: optional user.Member creator; // 创建人
    8: optional bool solved; // 是否已解答
}

struct PostDetail{
    1: optional i32 post_id;
    2: string title; // 标题
    4: list<course.Directory> directories; // 关联分组
    5: string content; // 正文
    6: optional string reply_content; // 解答正文
    7: optional list<user.Member> repliers; // 解答人
    8: optional bool reply_state; // 解答状态
    9: optional string updated_at; // 帖子最近修改时间（包括评论、编辑、回复等中最近的时间）
    10: optional string post_content_updated_at; // 帖子本体最新编辑时间
    11: optional string reply_content_updated_at; // 解答正文最新编辑时间
    12: optional bool is_locked; // 帖子是否锁定
    13: string type; // 类型; 枚举值： "note"-文章/笔记；"question"-提问
    14: optional string created_at; // 创建时间
    16: optional user.Member creator; // 创建人
    17: optional bool solved; // 是否已解答
    18: optional string last_replied_at; // 最近回复时间
    19: i32 comment_count; // 该帖子的评论数量
    20: bool liked; // 点过赞了
    21: optional string last_commented_at;
}

struct GetPostsRequest{
    1: i32 course_id;
    2: bool subscribed;
    3: i32 directory_id;
}

struct GetPostsResponse{
    1: base.Meta meta;
    2: list<Post> posts;
}

struct CreatePostResponse{
    1: base.Meta meta;
}

struct CreatePostRequest{
    1: string title; // 标题
    2: string abstract; // 正文缩略
    3: list<i32> directory_ids; // 关联分组
    4: string content; // 正文
    5: i32 course_id; // 隶属的课程号
    6: string type; // 类型; 枚举值： "note"-文章/笔记；"question"-提问
}

struct DeletePostRequest{
    1: i32 post_id;
}

struct DeletePostResponse{
    1: base.Meta meta;
}

struct GetPostDetailResponse{
    1: base.Meta meta;
    2: PostDetail post_detail;
}

struct GetPostDetailRequest{
    1: i32 post_id;
}

struct UpdatePostRequest{
    1: i32 post_id;
    2: string content;
    3: string title;
}

struct UpdatePostResponse{
    1: base.Meta meta;
}

struct ReplyPostQuestionRequest{
    1: i32 post_id;
    2: string reply_content;
}

struct ReplyPostQuestionResponse{
    1: base.Meta meta;
}

struct CreatePostDirectoryRelationResponse{
    1: i32 post_id;
    2: i32 directory_id;
    3: i32 course_id;
}

struct CreatePostDirectoryRelationRequest{
    1: base.Meta meta;
}

struct DeletePostDirectoryRelationRequest{
    1: i32 post_id;
    2: i32 directory_id;
    3: i32 post_directory_relation_id; // 要么传post_id和directory_id，要么传relation_id
}

struct DeletePostDirectoryRelationResponse{
    1: base.Meta meta;
}

service PostService{
    GetPostsResponse GetPosts(1: GetPostsRequest req)(api.post="/get_posts")
    CreatePostResponse CreatePost(1: CreatePostRequest req)(api.post="/post")
    DeletePostResponse DeletePost(1: DeletePostRequest req)(api.delete="/post")
    GetPostDetailResponse GetPostDetail(1: GetPostDetailRequest req)(api.post="/get_post_detail")
    UpdatePostResponse UpdatePostDetail(1: UpdatePostRequest req)(api.patch="/post") // 修改帖子的内容：标题、正文
    ReplyPostQuestionResponse ReplyPostQuestion(1: ReplyPostQuestionRequest req)(api.post="/reply_post_question") // 回答帖子里的问题

    CreatePostDirectoryRelationResponse CreatePostDirectoryRelation(1: CreatePostDirectoryRelationRequest req)(api.post="/post_directory_relation")
    DeletePostDirectoryRelationResponse DeletePostDirectoryRelation(1: DeletePostDirectoryRelationRequest req)(api.delete="/post_directory_relation")
}